package com.xhwl.logistics.controller.cent;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.personnel.StaffDTO;
import com.xhwl.common.query.cent.sdata.StaffQuery;
import com.xhwl.logistics.query.PageStaffQuery;
import com.xhwl.logistics.service.cent.IAccountService;
import com.xhwl.logistics.util.PageResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


@RestController
@Api(tags = "获取企业员工信息")
@Slf4j
@RequestMapping(value = "staff")
public class StaffController {

    @Autowired
    private IAccountService accountService;

    @ApiOperation(value = "分页获取员工信息")
    @PostMapping(value = "pageStaff")
    public ResultJson pageStaff(@RequestBody PageStaffQuery pageStaffQuery, @RequestHeader("projectId")Integer projectId
            , @RequestHeader("enterpriseId")Integer enterpriseId){
        StaffQuery staffQuery = new StaffQuery();
        if (ObjectUtil.isNotNull(projectId)) {
            staffQuery.setProjectId(Arrays.asList(projectId));
        }
        if (ObjectUtil.isNotNull(enterpriseId)) {
            staffQuery.setEnterpriseId(enterpriseId);
        }
        List<StaffDTO> list = accountService.list(staffQuery);
        Page<StaffDTO> page = accountService.page(staffQuery,PageResultUtils.getMyBatisPlusPage(pageStaffQuery.getCurrent().longValue(), pageStaffQuery.getSize().longValue()));
        return ResultJson.successWithResult(page);
    }
}
